<?php
namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ProductSkuResource extends JsonResource
{
    public function toArray($request)
    {
	    $resource = $this->resource;
    	
        return [
        	'id' => (int)$resource->id,
	        'product_id' => (int)$resource->product_id,
	        'name' => $resource->name,
	        'brief' => $resource->brief ?? '',
	        'pic_url' => img_path($resource->pic),
	        'attr_value' => $resource->attr_value,
	        'attr_value_index' => $resource->attr_value_index,
	        'attr_value_index_array' => $resource->getAttrValueIndexArray(),
	        'price' => $resource->price,
	        'price_vip' => $resource->price_vip,
	        'stock' => (int)$resource->stock,
	        'created_at' => (string)$resource->created_at,
	        
	        'product' => new ProductResource($this->whenLoaded('product')),
        ];
    }
}
